/******************************************************
 *                                                     
 *              Score System               
 *                                                     
 *******************************************************/

/**
 * SubjectTblDAO.java
 *
 * @author sundy
 * @version 0.0.1
 * lastModified 2011-01-01
 */

package com.sundy.daosupport;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.sundy.service.SubjectTbl;

/**
 * A data access object (DAO) providing persistence and search support for
 * SubjectTbl entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.sundy.service.SubjectTbl
 * @author MyEclipse Persistence Tools
 */

public class SubjectTblDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(SubjectTblDAO.class);
	// property constants
	public static final String CAPTION = "caption";
	public static final String DESC_ID = "descId";

	protected void initDao() {
		// do nothing
	}

	public void save(SubjectTbl transientInstance) {
		log.debug("saving SubjectTbl instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(SubjectTbl persistentInstance) {
		log.debug("deleting SubjectTbl instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public void delete(int id) {
		log.debug("deleting SubjectTbl instance");
		try {
			Object object = getHibernateTemplate().load(
					SubjectTbl.class.getName(), id);
			getHibernateTemplate().delete(object);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public SubjectTbl findById(java.lang.Integer id) {
		log.debug("getting SubjectTbl instance with id: " + id);
		try {
			SubjectTbl instance = (SubjectTbl) getHibernateTemplate().get(
					"com.sundy.service.SubjectTbl", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	@SuppressWarnings("unchecked")
	public List<SubjectTbl> findByExample(SubjectTbl instance) {
		log.debug("finding SubjectTbl instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	@SuppressWarnings("unchecked")
	public List<SubjectTbl> findByProperty(String propertyName, Object value) {
		log.debug("finding SubjectTbl instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from SubjectTbl as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<SubjectTbl> findByCaption(Object caption) {
		return findByProperty(CAPTION, caption);
	}

	public List<SubjectTbl> findByDescId(Object descId) {
		return findByProperty(DESC_ID, descId);
	}

	@SuppressWarnings("unchecked")
	public List<SubjectTbl> findAll() {
		log.debug("finding all SubjectTbl instances");
		try {
			String queryString = "from SubjectTbl";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public SubjectTbl merge(SubjectTbl detachedInstance) {
		log.debug("merging SubjectTbl instance");
		try {
			SubjectTbl result = (SubjectTbl) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(SubjectTbl instance) {
		log.debug("attaching dirty SubjectTbl instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(SubjectTbl instance) {
		log.debug("attaching clean SubjectTbl instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static SubjectTblDAO getFromApplicationContext(ApplicationContext ctx) {
		return (SubjectTblDAO) ctx.getBean("SubjectTblDAO");
	}
}